//
//  DetailTopView.m
//  SUZHOUBANK
//
//  Created by saberLily on 16/4/15.
//  Copyright © 2016年 RuiFeng-WGCC. All rights reserved.
//

#import "DetailTopView.h"
#import <AFNetworking/UIImageView+AFNetworking.h>
@interface DetailTopView()
@property (nonatomic,strong) UILabel *titleLabel; /**< <#desc#> */

@property (nonatomic,strong) UIButton *closeBtn; /**< 关闭 */
@property (nonatomic,strong) UIView *backView; /**< 背景 */
@property (nonatomic,strong) UIView *mainView; /**< 正片 */

@end
@implementation DetailTopView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeDataSource];
        [self initializeUserInterface];
    }
    return self;
}
#pragma mark - initializeDataSource 初始化数据源
-(void)initializeDataSource{
    
}

#pragma mark - initializeUserInterface 初始化用户界面
-(void)initializeUserInterface{
    
    [self.mainView addSubview:self.titleLabel];
    [self.mainView addSubview:self.detailImage];
    [self.mainView addSubview:self.closeBtn];
    [self addSubview:self.backView];

    [self addSubview:self.mainView];
    
}

-(void)reloadAllData{
    [self.detailImage setImageWithURL:[NSURL URLWithString:self.detailImageUrl]];
    self.titleLabel.text = self.detailTitle;
}

#pragma mark *** PrivateMethods ***
-(void)respondsToBtn:(UIButton *)sender{
    [self removeFromSuperview];
}
#pragma mark *** getters ***

-(UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc]initWithFrame:self.frame];
        _backView.backgroundColor = [UIColor blackColor];
        _backView.alpha = 0.5;
        
    }
    return _backView;
}
-(UIView *)mainView{
    if (!_mainView) {
        _mainView = [[UIView alloc]initWithFrame:CGRectMake(90, 80, 1200, 1000)];

        _mainView.layer.cornerRadius = 10.0f;
        _mainView.layer.shadowColor = [UIColor blackColor].CGColor;
        _mainView.layer.shadowOffset = CGSizeMake(-10, -10);
        _mainView.layer.shadowOpacity =0.7f;
        
        _mainView.backgroundColor = [UIColor whiteColor];
        
    }
    return _mainView;
}
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        
        CGFloat centerX =   [UIApplication sharedApplication].keyWindow.rootViewController.view.center.x;
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, 500, 50)];
        _titleLabel.center = CGPointMake(centerX, 40);
        _titleLabel.text = @"详 情";
        _titleLabel.font = [UIFont systemFontOfSize:40];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.backgroundColor = [UIColor whiteColor];
    }
    return _titleLabel;
}
-(UIImageView *)detailImage{
    if (!_detailImage) {
        _detailImage = [[UIImageView alloc] initWithFrame:CGRectMake(100, 150, 500, 400)];
        
        _detailImage.contentMode = UIViewContentModeScaleAspectFit;
        _detailImage.layer.masksToBounds = YES;

    }
    return _detailImage;
}
-(UIButton *)closeBtn{
    if (!_closeBtn) {
        _closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.mainView.bounds)-50, 0, 50, 50)];
        [_closeBtn setImage:[UIImage imageNamed:@"金融资讯_详情关闭"] forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(respondsToBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}
@end
